import { Visitor, Context, Node } from "./node";
export function createNode(): Node {
    const topNode = selector().findOne()
    const node = new CreaterVisitor().visit(topNode)
    return node;
}
export class CreaterVisitor implements Visitor {
    visit(node: UiObject): Node {
        const ctx = new Context()
        return this.createNode(node, ctx)
    }
    private createNode(node: UiObject, ctx: Context) {
        const parent = new Node(node).visit(this, ctx)
        ctx.set('parent', parent)
        if(node && node.children){
            parent.children = node.children().map(node => {
                const n = this.visit(node)
                n.parent = parent;
                return n;
            });
        }
        return parent;
    }
    visitNode(node: Node, ctx: Context) {
        return node;
    }
    
}